package com.guigu.www.controller;

import com.guigu.pojo.User;
import com.guigu.www.pojo.Roles;
import com.guigu.www.pojo.Users;
import com.guigu.www.service.RolesService;
import com.guigu.www.service.UserRolesService;
import com.guigu.www.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserRolesController {
    @Autowired
    UserRolesService service;
    @Autowired
    RolesService rolesservice;
    @Autowired
    UsersService usersService;
    @GetMapping("querybyroleid.action/{userid}")
    public Users querybyroleid(@PathVariable int userid){
        Users users=usersService.getById(userid);
        System.out.println(userid);
        List<Roles> rolesList=service.addUserRoles(userid);
        users.setRoles(rolesList);
        return users;
    }
    @PostMapping("addUserRoles.action")
    public Map useraddrole2(@RequestBody Users users){
        service.addUserRole(users);
        Map map=new HashMap();
        map.put("msg","赋予成功");
        return map;
    }
}
